home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
stretch
/
form1.frm
< prev
next >
Wrap
Text File
|
1994-07-07
|
8KB
|
229 lines
VERSION 2.00
Begin Form Form1
AutoRedraw = -1 'True
Caption = "Form1"
ClientHeight = 4605
ClientLeft = 1080
ClientTop = 1470
ClientWidth = 5925
Height = 5010
Left = 1020
LinkTopic = "Form1"
ScaleHeight = 4605
ScaleWidth = 5925
Top = 1125
Width = 6045
Begin CommandButton Command4
Caption = "Exit"
Height = 375
Left = 120
TabIndex = 6
Top = 2280
Width = 855
End
Begin PictureBox Picture3
Height = 315
Left = 120
ScaleHeight = 285
ScaleWidth = 825
TabIndex = 5
Top = 660
Width = 855
End
Begin CommandButton Command3
Caption = "Smaller"
Height = 375
Left = 120
TabIndex = 4
Top = 1860
Width = 855
End
Begin CommandButton Command2
Caption = "Bigger"
Height = 375
Left = 120
TabIndex = 3
Top = 1440
Width = 855
End
Begin CommandButton Command1
Caption = "Go"
Height = 375
Left = 120
TabIndex = 1
Top = 1020
Width = 855
End
Begin PictureBox Picture1
AutoRedraw = -1 'True
AutoSize = -1 'True
Height = 510
Left = 480
Picture = FORM1.FRX:0000
ScaleHeight = 480
ScaleWidth = 480
TabIndex = 0
Top = 60
Width = 510
End
Begin PictureBox Picture2
AutoRedraw = -1 'True
Height = 1215
Left = 1080
ScaleHeight = 79
ScaleMode = 3 'Pixel
ScaleWidth = 95
TabIndex = 2
Top = 60
Width = 1455
End
End
Sub Command1_Click ()
Dim PL As Single, PW As Single, PT As Single, PH As Single
Dim Color() As Long
Dim I As Single, J As Single, IOff As Single
Picture2.Cls 'Clear previous graphics
Picture2.Picture = LoadPicture() 'Clear previous picture
Picture2.Refresh
Picture3.Cls
Picture3.Scale (0, 0)-(100, 100) 'Makes status bar math easier for me.
PL = Picture1.ScaleLeft
PW = Picture1.ScaleWidth
PT = Picture1.ScaleTop
PH = Picture1.ScaleHeight
ReDim Color(PW - PL, PH - PT) As Long 'Resize the array to match Picture1's scale mode.
'Did it backwards just for fun.
Form1.MousePointer = 11
For I = PL To PW 'Left to right
For J = PT To PH 'Top to bottom
Color(I, J) = Picture1.Point(I, J) 'Get pixel color and assign to array.
Next
Picture3.Line (0, 0)-(I / PW * 100, 100), , BF 'Update status bar once each major loop.
Next
Picture3.Cls 'Clear staus bar for stretch loop.
For I = PL To PW 'Left to right
For J = PT To PH 'Top to bottom
On Error Resume Next 'Could someone tell me how to get this line out?
Picture2.Line (I, J)-(I + 1, J + 1), Color(I, J), BF 'Get color from array and draw one "pixel".
'Interesting stuff here. The line method will not
'draw the end point. And if you dont give it more
'than one "pixel" to draw, you get nothing.
'Picture2.Refresh ' Un-Comment this if you want to watch the stretched being drawn.
'DoEvents 'This one does the same thing, from a speed perspective.
Next
Picture3.Line (0, 0)-(I / PW * 100, 100), , BF 'Update status bar once each major loop.
Next
IOff = 1 / PH 'Corrects for slight difference between sizes
'of boxes in first and last grid rows and columns
'Doesn't work if Picture2 is too small
For I = 1 To PH - 1
Picture2.Line (0, I - IOff)-(PW, I - IOff) 'Draw horizontal lines
Next
IOff = 1 / PW 'Corrects for slight difference between
'locations of first and last grid lines
'Doesn't work if Picture2 is too small
For I = 1 To PW - 1
Picture2.Line (I - IOff, 0)-(I - IOff, PH) 'Draw verticle lines
Next
Picture2.Picture = Picture2.Image 'In case you want to save it
Picture2.Refresh
Form1.MousePointer = 0
'MsgBox Str$(I * J) 'This will tell you the number of pixels stored in the array.
End Sub
Sub Command2_Click ()
Picture2.Width = Picture2.Width * 1.5
Picture2.Height = Picture2.Height * 1.5
Picture2.Scale (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight)
'This, in combination with the Line...BF method, is what
'actually does the stretching (or shrinking). The effect,
'since Picture1's ScaleMode is pixels, is that you are
'simply drawing large, square pixels.
End Sub
Sub Command3_Click ()
Picture2.Width = Picture2.Width * .75
Picture2.Height = Picture2.Height * .75
Picture2.Scale (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight)
'This, in combination with the Line...BF method, is what
'actually does the stretching (or shrinking). The effect,
'since Picture1's ScaleMode is pixels, is that you are
'simply drawing large, square pixels.
End Sub
Sub Command4_Click ()
End
End Sub
Sub Form_Load ()
Picture1.ScaleMode = 3 'Pixels
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
Picture2.Scale (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight)
'The above line is also in the click events that
'resize Picture2, Commands 2 and 3
End Sub
Sub Picture1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox Str$(Picture1.Point(X, Y)) 'Get the color of the pixel under the cursor
End Sub
Sub Picture2_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox Str$(Picture2.Point(X, Y)) 'Get the color of the pixel under the cursor
End Sub
Sub Read_Me ()
'To use this thing, just run it and click "Bigger" a couple
'times, then click "Go".
'All the goodies are in the click events and picture mousedowns
'I know they should be in a sub or two, but after all, this
'was playtime. I just felt like seeing what the Point method
'was all about since most of the time I'm a database idiot.
'I also wanted to see what I could do with VB instead of
'using StretchBlt.
'I started out to do this by using an Image control to stretch
'the image but I ran into trouble when I tried to transfer
'the stretched image to a picture control (for the grid),
'since the image control has no image property(?!). Or for
'that matter an hWnd property. I also didn't feel like
'playing with hDCs. The result of all this negativity is what
'you see here. I hope you find it amusing.
'If for some strange reason you decide to use this in one of
'your apps, please thank me somewhere in it's documetation,
'or offer me a job (no joke).
'One question I have about it is this. If one were doing a
'MDI or other multiple image graphics app, would there be any
'benefit in assigning a third dimension to the array Color()
'in Command1 and assigning different images to that third
'dimension, or should each image have it's own array. I realize
'it would have to be declared elsewhere. Or should one always
're-read the original image. I realize memory could get full
'pretty fast but hey, Chicago's coming which means we'll all
'be customers at Memory Express <G>.
'If there isn't enough comments in the code, drop me a line
'at 72123,1243 or at AaronCr on AOL (aaroncr@aol.com) or
'leave me a note in the Basic Forum.
'Enjoy!
'Aaron P. Crouse
End Sub